import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public final class Socket implements Runnable {
	private int anInt379;
	private byte aByte380 = 2;
	private InputStream anInputStream381;
	private OutputStream anOutputStream382;
	private java.net.Socket aSocket383;
	private boolean aBoolean384 = false;
	Applet applet;
	private byte[] aByteArray386;
	private int anInt387;
	private int anInt388;
	private boolean aBoolean389 = false;
	private boolean aBoolean390 = false;

	public Socket(byte i, java.net.Socket socket, Applet applet) throws IOException {
		(this).applet = applet;
		aSocket383 = socket;
		if (i == aByte380) {
		} else {
			anInt379 = -5;
		}
		aSocket383.setSoTimeout(30000);
		aSocket383.setTcpNoDelay(true);
		anInputStream381 = aSocket383.getInputStream();
		anOutputStream382 = aSocket383.getOutputStream();
	}

	public void method224() {
		aBoolean384 = true;
		try {
			if (anInputStream381 != null) {
				anInputStream381.close();
			}
			if (anOutputStream382 != null) {
				anOutputStream382.close();
			}
			if (aSocket383 != null) {
				aSocket383.close();
			}
		} catch (IOException ioexception) {
			System.out.println("Error closing stream");
		}
		aBoolean389 = false;
		synchronized (this) {
			this.notify();
		}
		aByteArray386 = null;
	}

	public int method225() throws IOException {
		if (aBoolean384 == true) {
			return 0;
		}
		return anInputStream381.read();
	}

	public int method226() throws IOException {
		if (aBoolean384 == true) {
			return 0;
		}
		return anInputStream381.available();
	}

	public void method227(byte[] is, int i, int i_0_) throws IOException {
		if (aBoolean384 != true) {
			int i_1_;
			for (; i_0_ > 0; i_0_ -= i_1_) {
				i_1_ = anInputStream381.read(is, i, i_0_);
				if (i_1_ <= 0) {
					throw new IOException("EOF");
				}
				i += i_1_;
			}
		}
	}

	public void method228(int i, int i_2_, int i_3_, byte[] is) throws IOException {
		if (aBoolean384 != true) {
			if (aBoolean390) {
				aBoolean390 = false;
				throw new IOException("Error in writer thread");
			}
			if (aByteArray386 == null) {
				aByteArray386 = new byte[5000];
			}
			synchronized (this) {
				for (int i_4_ = 0; i_4_ < i_2_; i_4_++) {
					aByteArray386[anInt388] = is[i_4_ + i_3_];
					anInt388 = (anInt388 + 1) % 5000;
					if (anInt388 == (anInt387 + 4900) % 5000) {
						throw new IOException("buffer overflow");
					}
				}
				if (aBoolean389 == false) {
					aBoolean389 = true;
					(this).applet.method12(this, 3);
				}
				this.notify();
			}
			if (i != 0) {
			}
		}
	}

	@Override
	public void run() {
		while (aBoolean389 == true) {
			int i;
			int i_5_;
			synchronized (this) {
				if (anInt388 == anInt387) {
					try {
						this.wait();
					} catch (InterruptedException interruptedexception) {
					}
				}
				if (aBoolean389 == false) {
					break;
				}
				i = anInt387;
				if (anInt388 >= anInt387) {
					i_5_ = anInt388 - anInt387;
				} else {
					i_5_ = 5000 - anInt387;
				}
			}
			if (i_5_ > 0) {
				try {
					anOutputStream382.write(aByteArray386, i, i_5_);
				} catch (IOException ioexception) {
					aBoolean390 = true;
				}
				anInt387 = (anInt387 + i_5_) % 5000;
				try {
					if (anInt388 == anInt387) {
						anOutputStream382.flush();
					}
				} catch (IOException ioexception) {
					aBoolean390 = true;
				}
			}
		}
	}

	public void method229(boolean bool) {
		try {
			System.out.println("dummy:" + aBoolean384);
			System.out.println("tcycl:" + anInt387);
			System.out.println("tnum:" + anInt388);
			System.out.println("writer:" + aBoolean389);
			if (!bool) {
				System.out.println("ioerror:" + aBoolean390);
				try {
					System.out.println("available:" + method226());
				} catch (IOException ioexception) {
				}
			}
		} catch (RuntimeException runtimeexception) {
			Signlink.reporterror("8814, " + bool + ", " + runtimeexception.toString());
			throw new RuntimeException();
		}
	}
}
